<?php

// 本类由系统自动生成，仅供测试用途

class IndexAction extends Action {



public function index()

    {

		if(!isset($_SESSION[C('USER_AUTH_KEY')]))

		{

			$this->display();

		}

		else

		{

			//echo U('Admin/Manage/index1');

			$this->redirect('Admin/Manage/index');

		}

    }

   public function verify(){

        import('ORG.Util.Image');

        ob_end_clean(); 

        Image::buildImageVerify();

     }

	public function logout()

    { 



        if(isset($_SESSION[C('USER_AUTH_KEY')])) 

        {

			unset($_SESSION[C('USER_AUTH_KEY')]);

			unset($_SESSION);

			session_destroy();

            $this->assign("jumpUrl",__APP__.'/Admin/Index');

            $this->success('登出成功！');

        }

        else 

        {

			$this->assign("jumpUrl",__APP__.'/Admin/Index');

            $this->error('已经登出！');

        }

    }

	

	

	public function checklogin()

	{

		$name = $_POST['username'];

		$passwd = $_POST['passwd'];	
	
		if(session('verify') != md5($_POST['verify'])) 

		{

			$this->error('验证码错误！');

  		 }

		$user = D("admin");

		//$User->where('id=8')->find();这里的where 语句要注意一下，如果是其他字段的话后面一定要有单引号

		$userinfo = $user->where("adm_name ='$name'")->find();

		if(!empty($userinfo))

		{

			if($userinfo['adm_pass'] == m5($passwd))

			{

	

				$_SESSION[C('USER_NAME')]=$userinfo['adm_name'];

				$_SESSION[C('USER_AUTH_KEY')]=$userinfo['adm_id'];

				$_SESSION[C('USER_ROLE_ID')]=$userinfo['adm_role'];


				$user->where('adm_id='.$userinfo['adm_id'])->save(array('adm_time' =>date('Y-m-d H:i:s',time())));

				$this->assign("jumpUrl","__APP__/Admin/");

				$this->success('登陆成功！');

			}

			else

			{

				$this->assign("jumpUrl","__APP__/Admin/");

				$this->error('密码出错，请重新输入！');

			}		

		}

		else

		{

			$this->assign("jumpUrl","__APP__/Admin/");

			$this->error('用户名不存在！');

		}

	}



}